<?php
class basicInstrument extends model
{
    
    const ValidRule_id_instrument_isInt = 'ValidRule-id_instrument-isInt';
    const ValidRule_id_instrument_exists = 'ValidRule-id_instrument-exists';
    const ValidRule_instrumentType_isInt = 'ValidRule-instrumentType-isInt';
    const ValidRule_instrumentType_exists = 'ValidRule-instrumentType-exists';
    const ValidRule_isin_exists = 'ValidRule-isin-exists';
    const ValidRule_name_exists = 'ValidRule-name-exists';
    const ValidRule_name_isTextPl = 'ValidRule-name-isTextPl';

	
    public $id_instrument;
    public $instrumentType;
    public $isin;
    public $name;


	public static function loadModel($id=null, $join=null)
	{
		$obiekt = new Instrument($id, $join);
		if(!$obiekt ->isNull())
			return $obiekt;
		else return null;
	}
				
	public static function loadSpecialModel($where){
		$stmt = self::$pdo -> query("SELECT * FROM Instrument WHERE $where LIMIT 1;");
		$row = $stmt -> fetch(PDO::FETCH_ASSOC);
		if(!$row)
			return self::loadModel();
		$model = self::loadModel();
		$model -> SetValues($row);
		$model -> NewRecord = false;
		return $model;
	}

	public static function getAll($where=null)
	{
		return model::getAll('Instrument', $where);
	}

	public function __construct($id=null, $join = null)
	{
		parent::__construct($id, $join);
		$this -> labels = array(
            'id_instrument' => 'id_instrument', 
            'instrumentType' => 'instrumentType', 
            'isin' => 'isin', 
            'name' => 'name'
        );
	}

		
	public function getTableName()
	{
		return 'Instrument';
	}

	public function getPrimaryKey()
	{
		return 'id_instrument';
	}

	public function getColumns()
	{
		return array('id_instrument', 'instrumentType', 'isin', 'name');
	}

	protected function getBoolColumns()
	{
		return array();
	}

	public function getRules($ignore=array())
	{
		$rules = array(
            'ValidRule-id_instrument-isInt' => new ValidRule('id_instrument', isInt, array(&$this->id_instrument)),
            'ValidRule-id_instrument-exists' => new ValidRule('id_instrument', exists, array(&$this->id_instrument)),
            'ValidRule-instrumentType-isInt' => new ValidRule('instrumentType', isInt, array(&$this->instrumentType)),
            'ValidRule-instrumentType-exists' => new ValidRule('instrumentType', exists, array(&$this->instrumentType)),
            'ValidRule-isin-exists' => new ValidRule('isin', exists, array(&$this->isin)),
            'ValidRule-name-exists' => new ValidRule('name', exists, array(&$this->name)),
            'ValidRule-name-isTextPl' => new ValidRule('name', isTextPl, array(&$this->name))	
        );			

		if(!empty($ignore))
		{
			if(!is_array($ignore)) $ignore = array($ignore);
			foreach($ignore as $field)
			{
				unset($rules[$field]);
			}
		}
		return $rules;

	}

    protected function getJoinTables() {
        return array();
    }


}
?>